package com.lalilu.homework8.room;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

@Database(entities = {User.class}, version = 1)
public abstract class MyRoomDatabase extends RoomDatabase {
    private static volatile MyRoomDatabase instance = null;

    public MyRoomDatabase() {
    }

    public static MyRoomDatabase getInstance(Context context) {
        if (instance == null) {
            synchronized (MyRoomDatabase.class) {
                if (instance == null) {
                    instance = Room.databaseBuilder(context.getApplicationContext(),
                            MyRoomDatabase.class, "room")
                            .allowMainThreadQueries()
                            .build();
                }
            }
        }
        return instance;
    }

    public abstract UserDao userDao();
}
